package com.miracle9.game.dao;
import com.miracle9.game.bean.Pager;
import com.miracle9.game.entity.UserRegistLog;
import org.springframework.stereotype.Repository;

@Repository
public class UserRegistLogServiceDao extends SqlOperating<UserRegistLog, Integer>
{
  public int getQuantityByApplyStatus_0()
  {
    return q_CreateSqlInt("select count(*) from UserRegistLog where applyStatus=0", new Object[0]);
  }
  
  public Pager getByApplyStatus_0(Pager pager)
  {
    return q_CreateSqlsPager("from UserRegistLog where applyStatus =0", pager, new Object[0]);
  }
  
  public Pager getByDateInterval(String strStartDate, String strEndDate, Pager pager)
  {
    String dateFrom = strStartDate + " 00:00:00";
    String dateTo = strEndDate + " 23:59:59";
    return q_CreateSqlsPager("from UserRegistLog where applyStatus !=0  and operationDate>=? and operationDate<=? ", pager, new Object[] { dateFrom, dateTo });
  }
  
  public int getQuantityByUsername(String username)
  {
    int count = q_CreateSqlInt("select count(*) from UserRegistLog where username=?", new Object[] { username });
    return count;
  }
  
  public Integer saveReturnInteger(UserRegistLog userRegistLog)
  {
    return (Integer) saveReturn(userRegistLog);
  }
  
  public int getApplyStatusByUsername(String username)
  {
    int status = ((Integer)q_CreateSql("select applyStatus from UserRegistLog where username=? ", new Object[] { username }).uniqueResult()).intValue();
    return status;
  }
  
  public int getQuantityByIpAndDay(String ip, String day)
  {
    int count = q_CreateSqlInt("select count(*) from UserRegistLog where ip=? and applyDate like ?", new Object[] { ip, day + "%" });
    return count;
  }
  
  public void deletePastResult(String date)
  {
	  q_CreateSql("delete from UserRegistLog where applyDate<?", new Object[] { date }).executeUpdate();
  }
  
  public void cleanRegistApply()
  {
	  q_CreateSql("delete from UserRegistLog where applyStatus=0", new Object[0]).executeUpdate();
  }
}
